package com.ruoyi.api.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.api.dto.ServiceTypeStatDto;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.api.dto.ServiceTypeStatRespDto;
import com.ruoyi.api.dto.cleaning.resp.CleaningStatisticsRespDto;
import com.ruoyi.api.dto.greenery.resp.GreeneryStatisticsRespDto;
import com.ruoyi.api.dto.lamp.resp.LampStatisticsRespDto;
import com.ruoyi.api.dto.maintenance.resp.MaintenanceStatisticsRespDto;
import com.ruoyi.api.dto.park.resp.ParkStatisticsRespDto;
import com.ruoyi.api.service.CleaningStatService;
import com.ruoyi.api.service.GreeneryStatService;
import com.ruoyi.api.service.LampStatService;
import com.ruoyi.api.service.MaintenanceStatService;
import com.ruoyi.api.service.ParkStatService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.bo.DashboardBo;
import com.ruoyi.common.domain.vo.DashboardVo;
import com.ruoyi.common.service.DashboardService;

import lombok.RequiredArgsConstructor;

/**
 * test服务类型统计汇总
 *
 * @author cc
 * @date 2023-04-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/stat/statistics")
public class StatServiceTypeController {

	private final DashboardService dashboardService;
	private final LampStatService lampStatService;
	private final ParkStatService parkStatService;
	private final GreeneryStatService greeneryStatService;
	private final MaintenanceStatService maintenanceStatService;
	private final CleaningStatService cleaningStatService;
	
	@GetMapping("/serviceTypeStatistics")
	public Object serviceTypeStatistics() {
        ServiceTypeStatRespDto obj = new ServiceTypeStatRespDto();

        DashboardVo dvo = dashboardService.getDashboardInfo(new DashboardBo());

        List<ServiceTypeStatDto> data = new ArrayList<>();

        ServiceTypeStatDto dataDto1 = new ServiceTypeStatDto();
        dataDto1.setServiceType("清扫保洁");
        Map<String, Object> mapData1 = new HashMap<>();
        mapData1.put("streetPercentage", "0");
        dataDto1.setData(mapData1);
        data.add(dataDto1);

        ServiceTypeStatDto dataDto2 = new ServiceTypeStatDto();
        dataDto2.setServiceType("垃圾清运");
        Map<String, Object> mapData2 = new HashMap<>();
        mapData2.put("actualAttendance", "0");
        mapData2.put("accumulative", "0");
        dataDto2.setData(mapData2);
        data.add(dataDto2);

        ServiceTypeStatDto dataDto3 = new ServiceTypeStatDto();
        dataDto3.setServiceType("四害消杀");
        Map<String, Object> mapData3 = new HashMap<>();
        mapData3.put("actualAttendance", "0");
        mapData3.put("accumulative", "0");
        dataDto3.setData(mapData3);
        data.add(dataDto3);

        ServiceTypeStatDto dataDto4 = new ServiceTypeStatDto();
        dataDto4.setServiceType("一体化维修");
        Map<String, Object> mapData4 = new HashMap<>();
        mapData4.put("actualAttendance", "0");
        mapData4.put("accumulative", "0");
        dataDto4.setData(mapData4);
        data.add(dataDto4);

        ServiceTypeStatDto dataDto5 = new ServiceTypeStatDto();
        dataDto5.setServiceType("垃圾分类督导和投放点设施维护");
        Map<String, Object> mapData5 = new HashMap<>();
        mapData5.put("percentage", String.valueOf(dvo.getTotalSortingTodayCompletionRatio()));
        dataDto5.setData(mapData5);
        data.add(dataDto5);

        ServiceTypeStatDto dataDto6 = new ServiceTypeStatDto();
        dataDto6.setServiceType("市政公厕管养");
        Map<String, Object> mapData6 = new HashMap<>();
        mapData6.put("percentage", String.valueOf(dvo.getTotalToiletCompletionRatio()));
        dataDto6.setData(mapData6);
        data.add(dataDto6);

        ServiceTypeStatDto dataDto7 = new ServiceTypeStatDto();
        dataDto7.setServiceType("道路绿化管养");
        Map<String, Object> mapData7 = new HashMap<>();
        mapData7.put("percentage", "0");
        dataDto7.setData(mapData7);
        data.add(dataDto7);

        ServiceTypeStatDto dataDto8 = new ServiceTypeStatDto();
        dataDto8.setServiceType("公园管养");
        Map<String, Object> mapData8 = new HashMap<>();
        mapData8.put("percentage", "0");
        dataDto8.setData(mapData8);
        data.add(dataDto8);

        ServiceTypeStatDto dataDto9 = new ServiceTypeStatDto();
        dataDto9.setServiceType("路灯管养");
        Map<String, Object> mapData9 = new HashMap<>();
        mapData9.put("percentage", "0");
        dataDto9.setData(mapData9);
        data.add(dataDto9);

        obj.setData(data);
        return R.ok(obj);
//        R<ServiceTypeStatRespDto> res = JsonUtils.parseObject(HttpUtil.createGet("http://110.41.2.112:9090/api/stat/statistics/serviceTypeStatistics").execute().body(),new TypeReference<R<ServiceTypeStatRespDto>>() {});
//        if (null != res && res.getData() != null) {
//			DashboardVo dvo = dashboardService.getDashboardInfo(new DashboardBo());
//			if (res.getData().getData() != null) {
//				res.getData().getData().forEach(s -> {
//					switch (s.getServiceType()) {
//					case "垃圾收运":
//						s.getData().put("actualAttendance", String.valueOf(dvo.getRecycleTodayBarrelage()));
//						s.getData().put("accumulative", String.valueOf(dvo.getRecycleTotalBarrelage()));
//						s.setServiceType("垃圾清运");
//						break;
//					case "四害消杀":
//						s.getData().put("actualAttendance", String.valueOf(dvo.getTodayFrequency()));
//						s.getData().put("accumulative", String.valueOf(dvo.getTotalFrequency()));
//						break;
//					case "市政公厕管养":
//						s.getData().put("percentage", String.valueOf(dvo.getTotalToiletCompletionRatio()));
//						break;
//					case "垃圾分类督导和投放点设施维护":
//						s.getData().put("percentage", String.valueOf(dvo.getTotalSortingTodayCompletionRatio()));
//						break;
//					default:
//						break;
//					}
//				});
//			}
//        }
//        return res;

//			Map<String, Object> dataMap = res.getData();
//			if (null != dataMap) {
//				List<Map<String, Object>> listMap = (List<Map<String, Object>>) dataMap.get("data");
//				listMap.forEach(s -> {
//					Map<String, Object> data = (Map<String, Object>) s.get("data");
//					String serviceType = (String) s.get("serviceType");
//					if (null != data) {
//						switch (serviceType) {
//						case "垃圾收运":
//							data.put("actualAttendance", String.valueOf(dvo.getRecycleTodayBarrelage()));
//							data.put("accumulative", String.valueOf(dvo.getRecycleTotalBarrelage()));
//							s.put("serviceType", "垃圾清运");
//							break;
//						case "四害消杀":
//							data.put("actualAttendance", String.valueOf(dvo.getTodayFrequency()));
//							data.put("accumulative", String.valueOf(dvo.getTotalFrequency()));
//							break;
//						case "市政公厕管养":
//							data.put("percentage", String.valueOf(dvo.getTotalToiletCompletionRatio()));
//							break;
//						case "垃圾分类督导和投放点设施维护":
//							data.put("percentage", String.valueOf(dvo.getTotalSortingTodayCompletionRatio()));
//							s.put("serviceType", "垃圾分类督导");
//							break;
//						default:
//							break;
//						}
//
//					}
//				});
//			}
//
	}

	
	@GetMapping("/getCleaningDetailList")
	R<List<CleaningStatisticsRespDto>> getCleaningDetailList(@RequestParam(name = "date", defaultValue = "") String date,
			PageQuery pageQuery) {
		return R.ok(cleaningStatService.queryCleaningList(date, pageQuery).getRows());
	}
	
	@GetMapping("/getRecycleDetailList")
	R<List<Object>> getRecycleDetailList(@RequestParam(name = "date", defaultValue = "") String date) {
		return R.ok(new ArrayList<>());
	}

	@GetMapping("/getExterminationDetailList")
	R<List<Object>> getExterminationDetailList(
			@RequestParam(name = "date", defaultValue = "") String date) {
		return R.ok(new ArrayList<>());
	}

	@GetMapping("/getMaintenanceDetailList")
	R<List<MaintenanceStatisticsRespDto>> getMaintenanceDetailList(@RequestParam(name = "date", defaultValue = "") String date,
			PageQuery pageQuery) {
		return R.ok(maintenanceStatService.queryMaintenanceList(date, pageQuery).getRows());
	}

	@GetMapping("/getSortingDetailList")
	R<List<Object>> getSortingDetailList(@RequestParam(name = "date", defaultValue = "") String date) {
		return R.ok(new ArrayList<>());
	}

	@GetMapping("/getToiletDetailList")
	R<List<Object>> getToiletDetailList(@RequestParam(name = "date", defaultValue = "") String date) {
		return R.ok(new ArrayList<>());
	}

	@GetMapping("/getGreeneryDetailList")
	R<List<GreeneryStatisticsRespDto>> getGreeneryDetailList(@RequestParam(name = "date", defaultValue = "") String date,
			PageQuery pageQuery) {
		return R.ok(greeneryStatService.queryGreeneryMaintenanceList(date, pageQuery).getRows());
	}

	@GetMapping("/getParkDetailList")
	R<List<ParkStatisticsRespDto>> getParkDetailList(@RequestParam(name = "date", defaultValue = "") String date, 
			PageQuery pageQuery) {
		return R.ok(parkStatService.queryParkMaintenanceList(date, pageQuery).getRows());
	}

	@GetMapping("/getLampDetailList")
	R<List<LampStatisticsRespDto>> getLampDetailList(@RequestParam(name = "date", defaultValue = "") String date, 
			PageQuery pageQuery) {
		return R.ok(lampStatService.queryLampMaintenanceList(date, pageQuery).getRows());
	}
}
